#include "stdafx.h"
#include "ckField.h"
#include "ckFieldDef.h"
#include "ckValue.h"

namespace ck
{
	namespace data
	{
		Field::Field()
		{
			m_pValue = NULL;
			m_pFieldDef = NULL;
			
		}


		Field::~Field()
		{
			if (m_pFieldDef)
			{
				m_pFieldDef->Release();
				m_pFieldDef = NULL;
			}
			if (m_pValue)
			{
				m_pValue->Release();
				m_pValue = NULL;
			}
		}

		const char* Field::GetName()
		{
			return m_strName.c_str();
		}

		RESULTCODE Field::SetName(const char* szName)
		{
			if (szName)
			{
				m_strName = szName;
			}
			else
			{
				m_strName.clear();
			}
			return RC_SUCCESS;
		}

		const char* Field::GetDescription()
		{
			return m_strDescription.c_str();
		}

		RESULTCODE Field::SetDescription(const char* szDescription)
		{
			if (szDescription)
			{
				m_strDescription = szDescription;
			}
			else
			{
				m_strDescription.clear();
			}
			return RC_SUCCESS;
		}

		Value* Field::GetValue()
		{
			return m_pValue;
		}

		RESULTCODE Field::SetValue(Value* pValue)
		{
			if (m_pValue)
			{
				m_pValue->Release();
				m_pValue = NULL;
			}
			if (pValue)
			{
				m_pValue = pValue;
			}
			return RC_SUCCESS;
		}

		FieldDef* Field::GetFieldDef()
		{
			return m_pFieldDef;
		}

		RESULTCODE Field::SetFieldDef(FieldDef* pFieldDef)
		{
			if (m_pFieldDef)
			{
				m_pFieldDef->Release();
			}

			m_pFieldDef = pFieldDef;
			return RC_SUCCESS;
		}
	}
}


